<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

// 迅捷函数
$CI =&get_instance();

// 单字母懒人函数
function a($data)
{
	echo "<pre>";
	var_dump($data);exit;
}

function c( $name )
{
	global $CI;
	return $CI->config->item( $name );
}

function p( $name, $check = true, $jsoutput = false )
{
	global $CI;
	
	$CI->load->model("system_model");
	if($check) {
		//过滤词检测
		$pattern = $CI->system_model->get_filter_pattern();
		if($pattern != "") {
			if(is_string($CI->input->post( $name ))) {
				preg_match($pattern, $CI->input->post( $name ), $matches);
				if(!empty($matches[1])) {
					if($jsoutput) {
						exit("内容包含敏感词");
					}
					show_failed("内容包含敏感词");
				}
			}
		}
		//脚本攻击检测
		if(is_string($CI->input->post( $name ))) {
			$pattern = "/(<script>|<link>)/";
			preg_match($pattern, $CI->input->post( $name ), $matches);
			if(!empty($matches[1])) {
				if($jsoutput) {
					exit("内容包含非法字符");
				}
				show_failed("内容包含非法字符");
			}
		}
	}
	
	return $CI->input->post( $name );
}

function g( $name )
{
	global $CI;
	return $CI->input->get( $name );
}

function s( $name )
{
	global $CI;
	//$CI->load->database();//load database
	return $CI->db->escape( $name );
}

function u( $n )
{
	global $CI;
	if(is_null($CI)) $CI =&get_instance();
	return $CI->uri->segment( $n );
}

// for the textarea contaings rich text
function x( $name )
{
	$name = strip_tags( $name , '<a><img><u><b><strong><i><br/><br><p>' );
	global $CI;
	return $CI->input->xss_clean( $name );	
}

// no tag = clear all tag
// and change \r\n into br/
// for the textarea only contains text
function n( $name )
{
	$name = strip_tags( $name );
	$name = str_replace( "\n" , "<br/>" , $name );
	return $name; 
}

//输出javascript格式字符
function j($name)
{
	$name = strip_tags( $name );
	echo "document.write('".$name."');";exit;
}

//处理连接地址
function gurl($url)
{
	return site_url($url);
}



/* End of file */